package com.example.miniblog.service;

import com.example.miniblog.entity.Article;
import com.example.miniblog.entity.User;
import com.example.miniblog.mapper.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
//  ArticleService服务类
@Service
public class ArticleService implements IArticleService{

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public boolean addArticle(Article article) {
        int i = articleMapper.insert(article);
        return (i==1)?true:false;
    }

    @Override
    public boolean removeArticleById(String id) {
        int i = articleMapper.deleteById(id);
        return (i==1)?true:false;
    }

    @Override
    public boolean updateArticle(Article article) {
        int i = articleMapper.updateById(article);
        return (i==1)?true:false;
    }

    @Override
    public List<Article> getArticleByUsername(String Username) {
        List<Article> articles = articleMapper.selectList(null);
        return articles;
    }

    @Override
    public List<Article> getAll() {
        List<Article> articles = articleMapper.selectList(null);
        return articles;
    }

    @Override
    public Article getArticleById(String id) {
        return articleMapper.selectById(id);
    }
}
